#include "Reactor/Socket.h"
#include "Reactor/Acceptor.h"
#include "Reactor/EventLoop.h"
#include "Reactor/TcpServer.h"
#include "Reactor/TcpConnection.h"
#include "Reactor/EchoServer.h"
#include "Dictionary/InetAddress.h"
#include "Dictionary/DictProducer.h"
#include "Dictionary/KeyRecommander.h"
#include "Dictionary/Dictionary.h"
#include "PagePreprocess/DirScanner.h"
#include "PagePreprocess/WebPage.h"
#include "PagePreprocess/PageLib.h"
#include "PagePreprocess/PageLibPreprocessor.h"
#include "Mylogger.hh"
#include <iostream>
#include <vector>
#include <map>
#include <memory>
#include <functional>
#include <iostream>
#include <unistd.h>
#include <fstream>
#include <string>

using std::string;
using std::ostringstream;
using std::istringstream;
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::ifstream;

//离线阶段一，生成词典和索引
void modul_1()
{//离线阶段，生成词典和索引
    DictProducer file;
    file.buildEnDict("data/yuliao/english.txt");
    file.buildChDict();
    file.createIndex();
    file.Surch("我");
}

//离线阶段二，生成网页库
void modul_2(){
    //生成网页库
    // DirScanner dirs;
    // dirs.traverse("data/人民网语料");
    // FileProcessor fileproc;
    // PageLib pagelib(dirs,fileproc);
    // pagelib.create();

    //网页库预处理
    PageLibPreprocessor paglibpre;
    //paglibpre.Preprocessor();//网页库预处理
    paglibpre.bulidInvertIndex();//生成倒排索引
}

//在线阶段，启动服务器
void SearchEngine(){ 
    EchoServer server(4, 10, "192.168.254.129", 8888);
    server.start();
}
void test_Dictionary(){
    // Dictionary::getInstance()->print_dict();
    // cout << Dictionary::getInstance()->doQuery("我是");

    // Dictionary::getInstance()->destroy();


    KeyRecommander keyrecommander("我");
    keyrecommander.doQuery();
}
int main()
{   //test_Dictionary();
    
    SearchEngine();
    //modul_1();
    //modul_2();
    Mylogger::destroy();
    return 0;
}